<template>
  <div class="school">
    <h2>学校名称: {{ name }}</h2>
    <h2>学校地址：{{ address }}</h2>
  </div>
</template>

<script>
import pubsub from "pubsub-js"
export default ({
  name: 'school',
  data() {
    return {
      name: "尚硅谷",
      address: '北京',
    }
  },
  mounted() {
    this.pubId = pubsub.subscribe('hello', (msgName, data) => {
      console.log(this);

      // console.log('有人发布了hello消息', msgName, data);
    })
  },
  beforeDestroy() {
    //重点是这里的this 和 上面的 this.pubId
    pubsub.unsubscribe(this.pubId)
  },
  methods: {

  }
})
</script>

<style  lang="less" scoped>
.school {
  background-color: skyblue;
  padding: 5px;
}
</style>

